package com.witframework.soa.transform;

import javax.xml.xpath.XPathConstants;

import com.witframework.util.StringDigest;
import com.witframework.xml.XMLReader;

/**
 * 实体的XML格式数据的读取类，读取单个实体。
 * @author wuxinyang
 *
 */
public class XmlEntityReader {
	private XMLReader reader;
	public XmlEntityReader(String xml){
		reader=new XMLReader(xml);
	}
	/**
	 * 读取属性值
	 * @param property xml表示的实体(BaseEntity)的属性(property)名称
	 * @return String
	 */
	public String readStringValue(String property){
		return (String)reader.getValue("//object/"+property, XPathConstants.STRING);
	}
	/**
	 * 读取属性值
	 * @param property xml表示的实体(BaseEntity)的属性(property)名称
	 * @return Number
	 */
	public Number readNumberValue(String property){
		return (Number)reader.getValue("//object/"+property, XPathConstants.NUMBER);
	}
	/**
	 * 读取属性值
	 * @param property xml表示的实体(BaseEntity)的属性(property)名称
	 * @return byte[]
	 */
	public byte[] readBinaryValue(String property){
		String bytestr=(String)reader.getValue("//object/"+property, XPathConstants.STRING);
		if(bytestr!=null)
			return StringDigest.decodeBytes(bytestr);
		return null;
	}	
}
